//
//  HTSysParam.m
//  HTERPManApp
//
//  Created by standychen on 14-11-10.
//  Copyright (c) 2014年 HT. All rights reserved.
//

#import "HTSysParam.h"

#import "HTFrameKit.h"
#import "FMDB.h"

//系统参数类



static bool _autoLoginFlag=false;//自动登录标志  为是的在导航页面要重新校验登录数据，防止密码修改，服务器变更等情况

static NSString *_ptLoginUserid=@"";//平台登录用户代码

static NSString *_ptLoginUserName=@"";//平台登录用户名

static long _ptloginUserDid=0;//平台登录用户数据ID

static bool _ptManageFlag;//平台管理员标志

//static NSMutableArray *_sysInfoList=[[NSMutableArray alloc]init];//定义系统数据对象，存储系统控制相关的信息，自动退出重新访问服务器节点

static long _ptVendorDid=0;//平台客户数据ID

static NSString *_ptVendorAttn=@"";//平台客户简称

static NSString *_ptVendorID=@"";//平台客户编码

static NSString *_erpServer=@"";//ERP服务地址

static NSString *_erpInServer=@"";//ERP用户内网服务地址

static NSString *_erpVirDir=@"";//ERP服务虚拟目录

static NSString *_localpath=@"";//文档存放本地路径
static NSString *_netpath=@"";//文档存放网络路径

static NSString *_cityCode=@"";//城市编码
static NSString *_city=@"";//城市

static NSString *_userID=@"";//用户名

static NSString *_telNum=@"";//手机号
static NSString *_quitFlag=@"";//退出标识

static NSString *_localClubID=@"";//会所ID

static NSString *_localClubName=@"";//会所名称


static NSString *_erpOPID=@"";//ERP操作用户ID

static NSString *_clubID=@"";//会所ID

static NSString *_registrationID=@"";

static NSDate *_lastLoginTime;//最近一次用户登录

static int _refreshFlag=0;

static NSString *_upFlag=@"0";



@implementation HTSysParam


+(void)loadParamWithTelNum:(NSString *)value{
    _telNum=value;
}


+(void)loadParamWithQuitFlag:(NSString *)value{
    _quitFlag=value;
}


+(void)loadWithRegistrationID:(NSString *)value{
    _registrationID=value;
}

+(void)loadChangeClub:(NSString *)clubID initWithClubName:(NSString *)clubName{
    _localClubID=clubID;
    _localClubName=clubName;
}

+(void)loadParamWithRefreshFlag:(int)value{
    _refreshFlag=value;
}

+(void)loadParamWithUpFlag:(NSString*)value{
    _upFlag=value;
}


//设置登录参数 根据登录信息
+(void)loadParamWithLoginAction:(NSDictionary *)dict
{
    NSString *waitconvertint;
    long tempint;
    _ptLoginUserid=[dict objectForKey:@"ucode"];
    _ptLoginUserName=[dict objectForKey:@"uname"];
    waitconvertint=[dict objectForKey:@"uid"];
    _ptloginUserDid = [waitconvertint integerValue];
    _ptVendorID=[dict objectForKey:@"vcode"];
    _localpath=[dict objectForKey:@"LocalPath"];
     _netpath=[dict objectForKey:@"NetPath"];
    waitconvertint=[dict objectForKey:@"manageflag"];
    tempint=[waitconvertint integerValue];
    if(tempint==1)
    {
        _ptManageFlag=true;
    }
    else
    {
        _ptManageFlag=false;
    }
    
    
    
    waitconvertint=[dict objectForKey:@"vid"];
    _ptVendorDid = [waitconvertint integerValue];
    
    _ptVendorAttn=[dict objectForKey:@"vname"];
    _erpServer=[dict objectForKey:@"erpserver"];
    _erpInServer=[dict objectForKey:@"erpinserver"];
    _erpVirDir=[dict objectForKey:@"erpvirdir"];
    _erpOPID=[dict objectForKey:@"erpopid"];

    
}


//设置登录参数 根据登录信息
+(void)loadParamWithDefault:(NSDictionary *)dict
{
    
    _erpServer=[dict objectForKey:@"erpserver"];
    _erpVirDir=[dict objectForKey:@"erpvirdir"];

    
}

+(void)loadChangeCity:(NSDictionary *)dict{
    _cityCode=[dict objectForKey:@"cityCode"];
    _city=[dict objectForKey:@"city"];
}

+(void)loadParamWithClubID:(NSString *)value{
    _clubID=value;
}

//设置登录参数 从本地数据库读取
+(void)loadParamFormLocalDB
{
    [HTFrameSysUtils getFMDataBase:^(FMDatabase *db)
     {
         NSString *sql;
         sql=@"select DCode,DStrValue,DTimeValue,DIntValue FROM  t_param  order by did";
         //返回的是一个结果集
         FMResultSet *set = [db executeQuery:sql];
         
         //NSDictionary *dict=[[NSDictionary alloc] init];
         NSString *strWatiConvert;
         while ([set next]) {
             NSString *dcode=[set stringForColumn:@"DCode"];
             if ([dcode isEqualToString:@"ucode"]) {
                 _ptLoginUserid=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"uname"]) {
                 _ptLoginUserName=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"uid"]) {
                 strWatiConvert=[set stringForColumn:@"DIntValue"];
                 _ptloginUserDid=[strWatiConvert integerValue];
             }
             else if ([dcode isEqualToString:@"manageflag"]) {
                 strWatiConvert=[set stringForColumn:@"DIntValue"];
                 _ptManageFlag=[strWatiConvert boolValue];
             }
             else if ([dcode isEqualToString:@"vid"]) {
                 strWatiConvert=[set stringForColumn:@"DIntValue"];
                 _ptVendorDid=[strWatiConvert integerValue];
             }
             else if ([dcode isEqualToString:@"vname"]) {
                 _ptVendorAttn=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"vcode"]) {
                 _ptVendorID=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"erpserver"]) {
                 _erpServer=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"erpinserver"]) {
                 _erpInServer=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"erpvirdir"]) {
                 _erpVirDir=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"erpopid"]) {
                 _erpOPID=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"localpath"]) {
                 _erpOPID=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"netpath"]) {
                 _erpOPID=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"city"]) {
                 _city=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"cityCode"]) {
                 _cityCode=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"userID"]) {
                 _userID=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"telNum"]) {
                 _telNum=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"quitFlag"]) {
                 _quitFlag=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"localClubID"]) {
                 _localClubID=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"localClubName"]) {
                 _localClubName=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"clubID"]) {
                 _clubID=[set stringForColumn:@"DStrValue"];
             }
             else if ([dcode isEqualToString:@"refreshFlag"]) {
                 _refreshFlag=[[set stringForColumn:@"refreshFlag"]intValue];
             }
             else if ([dcode isEqualToString:@"upFlag"]) {
                 _upFlag=[set stringForColumn:@"upFlag"];
             }
             else if ([dcode isEqualToString:@"registrationID"]) {
                 _registrationID=[set stringForColumn:@"registrationID"];
             }

         }
         
     }];
}

//储存参数值到本地数据库内
+(void)saveParamToLocalDB
{
    [HTFrameSysUtils getFMDataBase:^(FMDatabase *db)
     {
         NSString *sql,*sqlint,*sqldate;
         sql=@"update t_param set DStrValue=? where DCode=?";
         sqlint=@"update t_param set DIntValue=? where DCode=?";
         sqldate=@"update t_param set DTimeValue=? where DCode=?";
         [db executeUpdate:sql,_ptLoginUserid,@"ucode"];
         [db executeUpdate:sql,_ptLoginUserName,@"uname"];
         [db executeUpdate:sqlint,_ptloginUserDid,@"uid"];
         [db executeUpdate:sqlint,_ptManageFlag,@"manageflag"];
         [db executeUpdate:sqlint,_ptVendorDid,@"vid"];
         [db executeUpdate:sql,_ptVendorAttn,@"vname"];
         [db executeUpdate:sql,_ptVendorID,@"vcode"];
         [db executeUpdate:sql,_erpServer,@"erpserver"];
         [db executeUpdate:sql,_erpInServer,@"erpinserver"];
         [db executeUpdate:sql,_erpVirDir,@"erpvirdir"];
         
         [db executeUpdate:sql,_erpOPID,@"erpopid"];
         [db executeUpdate:sql,_localpath,@"localpath"];
         [db executeUpdate:sql,_netpath,@"netpath"];
         [db executeUpdate:sql,_city,@"city"];
         [db executeUpdate:sql,_cityCode,@"cityCode"];
         [db executeUpdate:sql,_userID,@"userID"];
         [db executeUpdate:sql,_telNum,@"telNum"];
         [db executeUpdate:sql,_quitFlag,@"quitFlag"];
         [db executeUpdate:sql,_localClubID,@"localClubID"];
         [db executeUpdate:sql,_localClubName,@"localClubName"];
         [db executeUpdate:sql,_clubID,@"clubID"];
         [db executeUpdate:sql,_refreshFlag,@"refreshFlag"];
         [db executeUpdate:sql,_upFlag,@"upFlag"];
         [db executeUpdate:sql,_registrationID,@"registrationID"];
         
     }];
}

//{"flag":1,"info":"验证通过","vid":1,"vname":"恒泰App研发组","erpserver":"http://szht.8866.org:199","erpinserver":"http://192.168.0.56","erpvirdir":"htapperpwcf","uid":1,"uname":"Standy","erpopid":"L001","lastlogintime":"1900-01-01 00:00:00","manageflag":1}

+(BOOL)autoLoginFlag
{
    return _autoLoginFlag;
}

+(void)autoLoginFlagSet:(BOOL)b
{
    _autoLoginFlag=b;
}

+(NSString *)ptLoginUserid
{
    return _ptLoginUserid;
}

+(NSString *)ptLoginUserName
{
    return _ptLoginUserName;
}

+(NSString *)localpath
{
    return _localpath;
}

+(NSString *)netpath
{
    return _netpath;
}


+(long)ptloginUserDid
{
    return _ptloginUserDid;
}

+(BOOL)ptManageFlag
{
    return _ptManageFlag;
}


+(long)ptVendorDid
{
    return _ptVendorDid;
}

+(NSString *)city
{
    return _city;
}

+(NSString *)cityCode
{
    return _cityCode;
}

+(NSString *)userID
{
    return _userID;
}

+(NSString *)telNum
{
    return _telNum;
}

+(NSString *)quitFlag
{
    return _quitFlag;
}


+(NSString *)ptVendorAttn
{
    return _ptVendorAttn;
}
+(NSString *)ptVendorID
{
    return _ptVendorID;
}

+(NSString *)erpServer
{
    return _erpServer;
}

+(NSString *)erpInServer
{
    return _erpInServer;
}

+(NSString *)erpVirDir
{
    return _erpVirDir;
}

+(NSString *)erpOPID
{
    return _erpOPID;
}

+(NSDate *)lastLoginTime
{
    return _lastLoginTime;
}

+(NSString *)localClubID
{
    return _localClubID;
}

+(NSString *)localClubName
{
    return _localClubName;
}

+(NSString *)clubID
{
    return _clubID;
}

+(int)refreshFlag
{
    return _refreshFlag;
}

+(NSString *)upFlag
{
    return _upFlag;
}

+(NSString *)registrationID{
    return _registrationID;
}




@end
